import axios from "axios";
import {ElMessage} from "element-plus";

//c的
const httpInstance = axios.create({
    baseURL: 'http://localhost:8080',
    timeout: 5000
})

//axios请求拦截器
httpInstance.interceptors.request.use(
    config => {
        return config
    },
    error => {
        console.log(error)
        return Promise.reject(error)
    }
)

//axios响应拦截器
httpInstance.interceptors.response.use(
    resp => {
        if (resp.data.code === 233) {
            ElMessage({
                type: 'warning',
                message: resp.data.msg
            })
        }

        return resp.data
    },
    error => {
        console.log(error)
        return Promise.reject(error)
    }
)

export default httpInstance
